﻿using System;
using System.Web.Mvc;
using System.Linq;
using LOMBARDISPICK.Model.Repositories;
using LOMBARDISPICK.Model;
using LOMBARDISPICK.Domain.Services;
using LOMBARDISPICK.Domain.Infrastructure;
using LOMBARDISPICK.Web.Helpers;

namespace LOMBARDISPICK.Web.Controllers
{
	public class NFLTeamsController : BaseController<NFLTeam, INFLTeamsService>
	{
		private readonly INFLTeamsService ControllerService;

		public NFLTeamsController(
			INFLTeamsService ControllerService
			)
		{
			this.ControllerService = ControllerService;
		}

		private void ViewDataSelectLists()
		{
		}

		private void ViewDataSelectListsDefaultValue(int id)
		{
		}

		private void ViewDataDefaultValue(int id)
		{
		}

		//[View]
		public ActionResult Index()
		{
			return base.returnPartialView(this.ControllerService.getAllSorted());
		}

		//[View]
		public ActionResult Details(int id)
		{
			ViewDataDefaultValue(id);
			return base.returnPartialView(this.ControllerService.getById(id));
		}

		//[View?]
		public ActionResult GetImage(int id)
		{
			byte[] byteArray = this.ControllerService.getById(id).Helmet;
			if (byteArray != null)
				return File(byteArray, "image/jpeg");
			return null;
		}


		//[AdditionalPermissions(Roles = "Awsome,Test,Test2,Try")]
		//[Create]
		public ActionResult Create()
		{
			ViewDataSelectLists();
			return base.returnPartialView();
		}


		//[Create]
		[HttpPost]
		public ActionResult Create(NFLTeam data)
		{
			if (ModelState.IsValid)
			{
				ControllerService.create(data);
				return base.returnToIndex(data.NFLTeamsID);
			}
			ViewDataSelectLists();
			return View(data);
		}

		//[Edit]
		public ActionResult Edit(int id)
		{
			ViewDataSelectListsDefaultValue(id);
			return base.returnPartialView(this.ControllerService.getById(id));
		}

		//[Edit]
		[HttpPost]
		public ActionResult Edit(int id, FormCollection form)
		{
			var data = this.ControllerService.getById(id);
			if (TryUpdateModel(data))
			{
				this.ControllerService.save();
				return base.returnToIndex(id);
			}
			ViewDataSelectListsDefaultValue(id);
			return View(this.ControllerService.getById(id));
		}

		//[Delete]
		public ActionResult Delete(int id)
		{
			ViewDataDefaultValue(id);
			return base.returnPartialView(this.ControllerService.getById(id));
		}

		//[Delete]
		[HttpPost]
		public ActionResult Delete(int id, FormCollection collection)
		{
			this.ControllerService.delete(id);
			return base.returnToIndex(id);
		}		

	}
}
